import getCellTypeName from '../../../utils/getCellTypeName';
import {rightExpandImg, downExpandImg} from "."
import { Tools } from 'weaver-mobile';
const { getLabel } = Tools;

export default class FieldCellType extends window.GC.Spread.Sheets.CellTypes.Text {
    typeName = 'FieldCellType';
    label;
    fieldName;
    tableName = '0';
    fieldType = ['input', 'text', '200'];
    cellTypeData = {};
    fieldIndex;
    id;
    detailIndex;
    ds;
    table;
    field;
    type;
    condition;
    expandType;
    isCustom;
    uuid;
    constructor(fieldIndex) {
        super();
        if (fieldIndex !== void 0) {
            this.fieldIndex = fieldIndex;
            this.label = `${getLabel(502711, '字段') + fieldIndex}`;
            this.fieldName = `field${fieldIndex}`;
        }
    }

    paint(ctx, value, x, y, w, h, style, context) {
        if (!ctx) {
            return;
        }
        super.paint(ctx, value, x, y, w, h, style, context);
        if (!this.expandType) {
            return;
        }
        if (this.expandType == '1') {
                ctx.drawImage(rightExpandImg, x + 25, y + 8 / 2, 12, 12);
            
        } else if(this.expandType == '2') {
                ctx.drawImage(downExpandImg, x + 25, y + 8 / 2, 12, 12);
        }

    }

    get detailName() {
        return (!this.detailIndex || this.detailIndex === void 0) ? '主表' :this.isCustom =='custom' ?'自定义明细表': `明细${this.detailIndex}`
    }
    getValue() {
        return this.label && this.fieldName ? `${this.label}(${this.detailName}.${this.fieldName})` : '';
    }
    format(value, format, formattedData, context) {
        return this.getValue();
    }

    get cellTypeDatas() {
        return this.cellTypeData;
    }
    getCellTypeName = () => {
        return getCellTypeName(this.fieldType);
    }
    getFieldTypeImage = () => {
        const [htmltype] = this.fieldType;
        if (htmltype === 'input') {
            return '/formmode/exceldesign/image/controls/text2_wev8.png';
        } else if (htmltype === 'textarea') {
            return '/formmode/exceldesign/image/controls/textarea2_wev8.png';
        } else if (htmltype === 'browser') {
            if (this.fieldType.length > 1) {
                const { value = '1' } = this.fieldType[1] || {};
                if (value === '19') {
                    return '/formmode/exceldesign/image/controls/time2_wev8.png';
                } else if (value === '2' || value === '290') {
                    return '/formmode/exceldesign/image/controls/date2_wev8.png';
                }
            }
            return '/formmode/exceldesign/image/controls/browser2_wev8.png';
        } else if (htmltype === 'check') {
            return '/formmode/exceldesign/image/controls/checkbox2_wev8.png';
        } else if (htmltype === 'select') {
            return '/formmode/exceldesign/image/controls/select2_wev8.png';
        } else if (htmltype === 'upload') {
            return '/formmode/exceldesign/image/controls/affix2_wev8.png';
        }
        return '';
    }
}
